import router from './index.js'
import store from '@/store/index.js'


const vipList = ['/setting', '/aaa']
router.beforeEach(function (to, from, next) {
  const token = store.state.tokenInfo.token
  // console.log(token)
  if (vipList.includes(to.path)) {
    if (token) {
      next()
    } else {
      next('/login?backto=' + encodeURIComponent(to.fullPath))
      // fullPath属性比起path属性 多了查询字符串的参数
    }
  } else if (to.path === '/login') {
    if (token) {
      // console.log('已经登录过了')
      next('/')
    } else {
      next()
    }
  } else {
    next()
  }
})
router.afterEach(function (to, from) {
  // console.log('路由变化了,afterEach')
})
export default router
